<template>
  <div class="publishtemplate">
    <el-dialog title="发布模板" :visible.sync="stuDialogVisible" width="30%" center>
      <el-form :model="publishFormData">
        <el-form-item label="选择域名">
          <el-radio-group v-model="radioValue" @change="changeValue">
            <el-radio :label="1">zw</el-radio>
            <el-radio :label="2">vip</el-radio>
            <el-radio :label="3">free</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="colseDialogStu">取 消</el-button>
        <el-button type="primary" @click="surePublishTemplate">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { publistTemplate } from "@/api/basisMG";
export default {
  props: {
    stuDialogVisible: {
      type: Boolean
    },
  },
  data() {
    return {
      radioValue: "",
      publishFormData: {
        templateId: "",
        domainList: [],
      },
      defaultDomain: [
        {
          domain: "",
          plate: "",
        },
      ],
      domidarr: [],
    };
  },
  methods: {
    changeValue(val) {
      if (val === 1) {
        this.defaultDomain[0].domain = "zw";
      } else if (val === 2) {
        this.defaultDomain[0].domain = "vip";
      } else {
        this.defaultDomain[0].domain = "free";
      }
    },
    showPublish(row) {
      this.publishFormData.templateId = row.id;
    },
    surePublishTemplate() {
      this.$confirm("要发布该模板吗", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          this.publishFormData.domainList = this.defaultDomain;
          const data = await publistTemplate(this.publishFormData);
          if (data.code != 200) return this.$message.error("操作失败请稍后重试");
          this.$message({
            type: "success",
            message: "发布成功!",
          });
          this.emitList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "模板数据对应页面数据为空!",
          });
        });
    },
    colseDialogStu () {
      this.$emit("colseDialogStu");
    },
    emitList() {
      this.$emit("publistList");
    }
  }
};
</script>
<style lang="scss"></style>
